const rl = require("readline").createInterface({ input: process.stdin })

// 识别有效的IP地址和掩码并进行分类统计
// 统计A、B、C、D、E、错误IP地址或错误掩码、私有IP的个数，之间以空格隔开。

let count_a = 0
let count_b = 0
let count_c = 0
let count_d = 0
let count_e = 0
let count_error = 0
let count_private = 0

rl.on('line', (line) => {
  // if (line === 'end') {
  //   rl.close()
  //   return;
  // }
  const [ipStr, maskStr] = line.split('~')

  // 验证ip地址
  const ips = commonValidate(ipStr)
  if (!ips) {
    count_error ++
    return
  }

  if (ips[0] === 0 || ips[0] === 127) return;

  // 验证掩码
  const masks = commonValidate(maskStr, 2)
  if (!masks || !validateMask(masks)) {
    count_error ++
    return
  }

  // 分类ip地址
  getIpCount(ips)
})

rl.on('close', () => {
  console.log(`${count_a} ${count_b} ${count_c} ${count_d} ${count_e} ${count_error} ${count_private}`)
})

function getIpCount (ips) {
  const [a, b, c, d] = ips
  if (a === 0 || a === 127) return

  if (a >= 1 && a <= 126) {
    count_a ++
    if (a === 10) {
      count_private ++
    }
  } else if (a >= 128 && a <= 191) {
    count_b ++
    if (a === 172 && (b >= 16 && b <= 31)) {
      count_private ++
    }
  } else if (a >= 192 && a <= 223) {
    count_c ++
    if (a === 192 && b === 168) {
      count_private ++
    }
  } else if (a >= 224 && a <= 239) {
    count_d ++
  } else if (a >= 240 && a <= 255) {
    count_e ++
  }
}

/* 验证子网掩码是否合法 */
function validateMask (masks) {
  const binaryStr = masks.join('')

  const len = binaryStr.length
  const first = binaryStr.charAt(0)
  const last = binaryStr.charAt(len - 1)

  if (first === '0') return false

  if (first === '1' && last === '1') return false

  const fns = {
    is_1 (c) {
      return c === '1'
    },
    is_0 (c) {
      return c === '0'
    }
  }
  let type = 'is_1'
  for (let i = 0; i < len; i ++) {
    const c = binaryStr.charAt(i)

    if (c === '0') {
      type = 'is_0'
    }

    if (!fns[type](c)) return false
  }

  return true
}

function commonValidate (str, feed = 10) {
  const cuts = str.split('.')
  if (cuts.length !== 4) return false
  for (const cut of cuts) {
    if (!validateCut(cut)) return false
  }
  return cuts.map(c => feed === 2 ? ('' + parseInt(c).toString(2)).padStart(8, '0') : parseInt(c))
}

function validateCut (cut) {
  if (!cut || cut.length > 3) return false

  for (let i = 0; i < cut.length; i ++) {
    const c = cut.charAt(i)
    if (!(c >=0 && c <= 9)) return false
  }

  if (cut > 255) return false

  return true
}

// const ipObj = {
//   is_a (ipCuts) {
//     const [a, b, c, d] = ipCuts
//     if (
//       (a >= 1 && a <= 126) &&
//       (b >= 0 && b <= 255) &&
//       (c >= 0 && c <= 255) &&
//       (d >= 0 && d <= 255)
//     ) {
//       count_a ++
//       return true
//     }
//     return false
//   },
//   is_b (ipCuts) {
//     const [a, b, c, d] = ipCuts
//     if (
//       (a >= 128 && a <= 191) &&
//       (b >= 0 && b <= 255) &&
//       (c >= 0 && c <= 255) &&
//       (d >= 0 && d <= 255)
//     ) {
//       count_b ++
//       return true
//     }
//     return false
//   },
//   is_c (ipCuts) {
//     const [a, b, c, d] = ipCuts
//     if (
//       (a >= 192 && a <= 223) &&
//       (b >= 0 && b <= 255) &&
//       (c >= 0 && c <= 255) &&
//       (d >= 0 && d <= 255)
//     ) {
//       count_c ++
//       return true
//     }
//     return false
//   },
//   is_d (ipCuts) {
//     const [a, b, c, d] = ipCuts
//     if (
//       (a >= 224 && a <= 239) &&
//       (b >= 0 && b <= 255) &&
//       (c >= 0 && c <= 255) &&
//       (d >= 0 && d <= 255)
//     ) {
//       count_d ++
//       return true
//     }
//     return false
//   },
//   is_e (ipCuts) {
//     const [a, b, c, d] = ipCuts
//     if (
//       (a >= 240 && a <= 255) &&
//       (b >= 0 && b <= 255) &&
//       (c >= 0 && c <= 255) &&
//       (d >= 0 && d <= 255)
//     ) {
//       count_e ++
//       return true
//     }
//     return false
//   },
//   is_private (ipCuts) {
//     const [a, b, c, d] = ipCuts
//     if (
//       ((a === 10) && (b >= 0 && b <= 255) && (c >= 0 && c <= 255) && (d >= 0 && d <= 255)) ||
//       ((a === 172) && (b >= 16 && b <= 31) && (c >= 0 && c <= 255) && (d >= 0 && d <= 255)) ||
//       ((a === 192) && (b === 168) && (c >= 0 && c <= 255) && (d >= 0 && d <= 255))
//     ) {
//       count_private ++
//       return true
//     }
//     return false
//   }
// }
